from sqlalchemy import Column, Integer, String, Float, DateTime, Text, ForeignKey
from sqlalchemy.orm import relationship
from app.database.database import Base

class Winery(Base):
    __tablename__ = "wineries"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, index=True)
    location = Column(String)
    contact = Column(String)
    description = Column(Text)

class Vineyard(Base):
    __tablename__ = "vineyards"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, index=True)
    area = Column(Float)
    grape_variety = Column(String)
    planting_year = Column(String)
    soil_type = Column(String)
    location = Column(String)

class Harvest(Base):
    __tablename__ = "harvests"
    
    id = Column(Integer, primary_key=True, index=True)
    vineyard_name = Column(String, index=True)
    harvest_date = Column(String)
    quantity = Column(Float)
    quality_grade = Column(String)
    harvest_method = Column(String)
    weather = Column(String)
    notes = Column(Text)

class Preprocessing(Base):
    __tablename__ = "preprocessings"
    
    id = Column(Integer, primary_key=True, index=True)
    batch_number = Column(String, index=True)
    process_date = Column(String)
    process_type = Column(String)
    temperature = Column(Float)
    duration = Column(Float)
    operator = Column(String)
    notes = Column(Text)

class Fermentation(Base):
    __tablename__ = "fermentations"
    
    id = Column(Integer, primary_key=True, index=True)
    batch_number = Column(String, index=True)
    start_date = Column(String)
    end_date = Column(String)
    temperature = Column(Float)
    yeast_type = Column(String)
    alcohol_content = Column(Float)
    status = Column(String)

class Storage(Base):
    __tablename__ = "storages"
    
    id = Column(Integer, primary_key=True, index=True)
    batch_number = Column(String, index=True)
    storage_date = Column(String)
    storage_type = Column(String)
    temperature = Column(Float)
    humidity = Column(Float)
    duration = Column(String)
    notes = Column(Text)

class Bottling(Base):
    __tablename__ = "bottlings"
    
    id = Column(Integer, primary_key=True, index=True)
    batch_number = Column(String, index=True)
    bottling_date = Column(String)
    bottle_type = Column(String)
    quantity = Column(Integer)
    label_info = Column(String)
    packaging_type = Column(String)
    notes = Column(Text)

class QualityCheck(Base):
    __tablename__ = "quality_checks"
    
    id = Column(Integer, primary_key=True, index=True)
    batch_number = Column(String, index=True)
    check_date = Column(String)
    inspector = Column(String)
    alcohol_content = Column(Float)
    acidity = Column(Float)
    sugar_content = Column(Float)
    result = Column(String)
    notes = Column(Text)

class Order(Base):
    __tablename__ = "orders"
    
    id = Column(Integer, primary_key=True, index=True)
    order_number = Column(String, index=True)
    customer_name = Column(String)
    product_name = Column(String)
    quantity = Column(Integer)
    order_date = Column(String)
    delivery_date = Column(String)
    status = Column(String)
    notes = Column(Text)

class Logistics(Base):
    __tablename__ = "logistics"
    
    id = Column(Integer, primary_key=True, index=True)
    tracking_number = Column(String, index=True)
    order_number = Column(String)
    carrier = Column(String)
    shipping_date = Column(String)
    delivery_date = Column(String)
    status = Column(String)
    notes = Column(Text)

class OperationLog(Base):
    __tablename__ = "operation_logs"

    id = Column(Integer, primary_key=True, index=True)
    entity = Column(String, index=True)  # 模块/实体名
    action = Column(String, index=True)  # create/update/delete/bulk-delete
    entity_id = Column(Integer, index=True)
    detail = Column(Text)
    timestamp = Column(String, index=True)
    operator = Column(String, default="system")
